package spark

import org.apache.spark.sql.SparkSession

/**
  * @author pinker on 2018/6/11
  */
object FindLongestString {
  val hivePath = "D:/spark/hive/"

  def findLonger(str1: String, str2: String): String = {
    var str = str1
    if (str2.size > str1.size) {
      str = str2
    }
    str
  }

  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder()
      .appName("findLongestString")
      .master("local[*]")
      .config("spark.sql.warehouse.dir", hivePath)
      .getOrCreate()
    val sc = spark.sparkContext
    sc.setLogLevel("ERROR")
    val datas = sc.parallelize(Seq("hs", "hotk", "eotk", "dormitory", "semi", "shenzhen"), 3)
    val result = datas.reduce((str1, str2) => {
      println(str1 + "->" + str2)
      findLonger(str1, str2)
    })
    result.foreach(println)
  }
}
